from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-11 14:10:08.475951
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 11, Apr, 2021
Time: 14:10:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4524
Nobs: 258.000 HQIC: -48.1935
Log likelihood: 3076.47 FPE: 7.13778e-22
AIC: -48.6918 Det(Omega_mle): 5.06906e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.443833 0.125385 3.540 0.000
L1.Burgenland 0.071424 0.062152 1.149 0.250
L1.Kärnten -0.221094 0.053956 -4.098 0.000
L1.Niederösterreich 0.072788 0.136613 0.533 0.594
L1.Oberösterreich 0.216299 0.127378 1.698 0.089
L1.Salzburg 0.271880 0.070030 3.882 0.000
L1.Steiermark 0.132161 0.089384 1.479 0.139
L1.Tirol 0.121546 0.061374 1.980 0.048
L1.Vorarlberg -0.032987 0.056708 -0.582 0.561
L1.Wien -0.063990 0.116130 -0.551 0.582
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488050 0.147898 3.300 0.001
L1.Burgenland -0.002071 0.073311 -0.028 0.977
L1.Kärnten 0.331039 0.063643 5.201 0.000
L1.Niederösterreich 0.086779 0.161142 0.539 0.590
L1.Oberösterreich -0.066478 0.150250 -0.442 0.658
L1.Salzburg 0.220427 0.082604 2.668 0.008
L1.Steiermark 0.110089 0.105433 1.044 0.296
L1.Tirol 0.142440 0.072394 1.968 0.049
L1.Vorarlberg 0.153801 0.066890 2.299 0.021
L1.Wien -0.451459 0.136981 -3.296 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.289328 0.063287 4.572 0.000
L1.Burgenland 0.092982 0.031371 2.964 0.003
L1.Kärnten -0.016645 0.027234 -0.611 0.541
L1.Niederösterreich 0.065414 0.068955 0.949 0.343
L1.Oberösterreich 0.273533 0.064293 4.254 0.000
L1.Salzburg 0.023614 0.035347 0.668 0.504
L1.Steiermark 0.010579 0.045116 0.234 0.815
L1.Tirol 0.072882 0.030978 2.353 0.019
L1.Vorarlberg 0.081001 0.028623 2.830 0.005
L1.Wien 0.111620 0.058616 1.904 0.057
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219553 0.061921 3.546 0.000
L1.Burgenland 0.020793 0.030694 0.677 0.498
L1.Kärnten 0.008616 0.026646 0.323 0.746
L1.Niederösterreich 0.047247 0.067467 0.700 0.484
L1.Oberösterreich 0.403352 0.062906 6.412 0.000
L1.Salzburg 0.082767 0.034585 2.393 0.017
L1.Steiermark 0.130195 0.044143 2.949 0.003
L1.Tirol 0.050446 0.030310 1.664 0.096
L1.Vorarlberg 0.084253 0.028005 3.008 0.003
L1.Wien -0.047048 0.057351 -0.820 0.412
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.507865 0.120925 4.200 0.000
L1.Burgenland 0.087129 0.059941 1.454 0.146
L1.Kärnten 0.010356 0.052037 0.199 0.842
L1.Niederösterreich -0.009393 0.131755 -0.071 0.943
L1.Oberösterreich 0.136365 0.122848 1.110 0.267
L1.Salzburg 0.058626 0.067540 0.868 0.385
L1.Steiermark 0.068189 0.086205 0.791 0.429
L1.Tirol 0.214167 0.059191 3.618 0.000
L1.Vorarlberg 0.031829 0.054691 0.582 0.561
L1.Wien -0.097013 0.112000 -0.866 0.386
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189754 0.095577 1.985 0.047
L1.Burgenland -0.014781 0.047376 -0.312 0.755
L1.Kärnten -0.009610 0.041129 -0.234 0.815
L1.Niederösterreich -0.016246 0.104136 -0.156 0.876
L1.Oberösterreich 0.404687 0.097097 4.168 0.000
L1.Salzburg 0.017584 0.053382 0.329 0.742
L1.Steiermark -0.018051 0.068135 -0.265 0.791
L1.Tirol 0.160243 0.046784 3.425 0.001
L1.Vorarlberg 0.052509 0.043227 1.215 0.224
L1.Wien 0.238927 0.088522 2.699 0.007
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.239928 0.116433 2.061 0.039
L1.Burgenland 0.020280 0.057715 0.351 0.725
L1.Kärnten -0.067625 0.050104 -1.350 0.177
L1.Niederösterreich -0.063452 0.126860 -0.500 0.617
L1.Oberösterreich 0.017559 0.118285 0.148 0.882
L1.Salzburg 0.082004 0.065031 1.261 0.207
L1.Steiermark 0.335749 0.083003 4.045 0.000
L1.Tirol 0.461683 0.056992 8.101 0.000
L1.Vorarlberg 0.146826 0.052660 2.788 0.005
L1.Wien -0.168688 0.107839 -1.564 0.118
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162328 0.138172 1.175 0.240
L1.Burgenland 0.043309 0.068490 0.632 0.527
L1.Kärnten -0.073719 0.059458 -1.240 0.215
L1.Niederösterreich 0.147670 0.150546 0.981 0.327
L1.Oberösterreich 0.007703 0.140370 0.055 0.956
L1.Salzburg 0.204310 0.077173 2.647 0.008
L1.Steiermark 0.121644 0.098500 1.235 0.217
L1.Tirol 0.055595 0.067633 0.822 0.411
L1.Vorarlberg 0.100896 0.062492 1.615 0.106
L1.Wien 0.235646 0.127974 1.841 0.066
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.579539 0.074752 7.753 0.000
L1.Burgenland -0.037667 0.037054 -1.017 0.309
L1.Kärnten -0.024838 0.032167 -0.772 0.440
L1.Niederösterreich 0.028046 0.081446 0.344 0.731
L1.Oberösterreich 0.324817 0.075940 4.277 0.000
L1.Salzburg 0.020398 0.041751 0.489 0.625
L1.Steiermark -0.035870 0.053289 -0.673 0.501
L1.Tirol 0.088124 0.036590 2.408 0.016
L1.Vorarlberg 0.109785 0.033808 3.247 0.001
L1.Wien -0.044854 0.069234 -0.648 0.517
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.145150 0.074793 0.165347 0.221398 0.081033 0.083480 0.004913 0.154479
Kärnten 0.145150 1.000000 0.034673 0.203513 0.178775 -0.060306 0.163058 0.026541 0.305231
Niederösterreich 0.074793 0.034673 1.000000 0.240055 0.075374 0.327539 0.141321 0.026600 0.295016
Oberösterreich 0.165347 0.203513 0.240055 1.000000 0.300619 0.268268 0.089443 0.061070 0.134308
Salzburg 0.221398 0.178775 0.075374 0.300619 1.000000 0.153916 0.052856 0.089586 0.003142
Steiermark 0.081033 -0.060306 0.327539 0.268268 0.153916 1.000000 0.105173 0.096208 -0.108570
Tirol 0.083480 0.163058 0.141321 0.089443 0.052856 0.105173 1.000000 0.162284 0.147243
Vorarlberg 0.004913 0.026541 0.026600 0.061070 0.089586 0.096208 0.162284 1.000000 -0.001172
Wien 0.154479 0.305231 0.295016 0.134308 0.003142 -0.108570 0.147243 -0.001172 1.000000